#pragma once
#include <unordered_map>
namespace rpc
{
    // 消息字段,方便后期维护
    const char* KEY_METHOD = "method";
    const char* KEY_PARAMS = "parameters";
    const char* KEY_TOPIC_KEY = "topic_key";
    const char* KEY_TOPIC_MSG = "topic_msg";
    const char* KEY_OPTYPE = "optype";
    const char* KEY_HOST   = "host";
    const char* KEY_HOST_IP = "ip";
    const char* KEY_HOST_PORT = "port";
    const char* KEY_RCODE  = "rcode";
    const char* KEY_RESULT = "result";

    // 消息类型
    enum class MType
    {
        REQ_RPC = 0,
        RSP_RPC,
        REQ_TOPIC,
        RSP_TOPIC,
        REQ_SERVICE,
        RSP_SERVICE
    };
    // 回复类型
    enum class RCode
    {
        RCODE_OK = 0,
        RCODE_PARSE_FAILED,
        RCODE_ERROR_MSGTYPE,
        RCODE_INVALID_MSG,
        RCODE_DISCONNECTED,
        RCODE_INVALID_PARAMS,
        RCODE_NOT_FOUND_SERVICE,
        RCODE_INVALID_OPTYPE,
        RCODE_NOT_FOUND_TOPIC,
        RCODE_INTERNAL_ERROR
    };
    // 错误原因
    static const char* ErrReason(RCode code)
    {
        static std::unordered_map<RCode, const char*> err_map = {
            {RCode::RCODE_OK, "success handle!"},
            {RCode::RCODE_PARSE_FAILED, "message analysis fail!"},
            {RCode::RCODE_ERROR_MSGTYPE, "message type error!"},
            {RCode::RCODE_INVALID_MSG, "invalid message!"},
            {RCode::RCODE_DISCONNECTED, "disconnect!"},
            {RCode::RCODE_INVALID_PARAMS, "invalid rpc parameter!"},
            {RCode::RCODE_NOT_FOUND_SERVICE, "not find correspondent parameter!"},
            {RCode::RCODE_INVALID_OPTYPE, "invalid operator correspondent type!"},
            {RCode::RCODE_NOT_FOUND_TOPIC, "not find type"},
            {RCode::RCODE_INTERNAL_ERROR, "inner error"}
        };
        auto it = err_map.find(code);
        if(it == err_map.end())
            return " unknow error!";
        return it->second;
    }
    // 处理类型
    enum class RType {
        REQ_ASYNC = 0, //异步
        REQ_CALLBACK //同步
    };
    // 操作类型
    enum class TopicOptype {
        TOPIC_CREATE = 0,
        TOPIC_REMOVE,
        TOPIC_SUBSCRIBE,
        TOPIC_CANCEL,
        TOPIC_PUBLISH
    };
    // 服务类型
    enum class ServiceOptype {
        SERVICE_REGISTRY = 0,
        SERVICE_DISCOVERY,
        SERVICE_ONLINE,
        SERVICE_OFFLINE,
        SERVICE_UNKNOW
    };
}